#coding=utf-8
#Boa:Dialog:DlgDelivery

import wx

from MyListCtrl import MyListCtrlDelivery
from product import CDataDelivery

def create(parent):
    return DlgDelivery(parent)

[wxID_DLGDELIVERY, wxID_DLGDELIVERYBTNDEL, wxID_DLGDELIVERYBTNEDIT, 
 wxID_DLGDELIVERYBTNNEW, 
] = [wx.NewId() for _init_ctrls in range(4)]

class DlgDelivery(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGDELIVERY, name=u'DlgDelivery',
              parent=prnt, pos=wx.Point(335, 214), size=wx.Size(665, 509),
              style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u914d\u9001\u65b9\u5f0f\u9009\u62e9')
        self.SetClientSize(wx.Size(657, 475))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.btnNew = wx.Button(id=wxID_DLGDELIVERYBTNNEW,
              label=u'\u65b0\u5efa', name=u'btnNew', parent=self,
              pos=wx.Point(8, 8), size=wx.Size(93, 26), style=0)
        self.btnNew.Bind(wx.EVT_BUTTON, self.OnBtnNewButton,
              id=wxID_DLGDELIVERYBTNNEW)

        self.btnEdit = wx.Button(id=wxID_DLGDELIVERYBTNEDIT,
              label=u'\u4fee\u6539', name=u'btnEdit', parent=self,
              pos=wx.Point(136, 8), size=wx.Size(93, 26), style=0)
        self.btnEdit.Bind(wx.EVT_BUTTON, self.OnBtnEditButton,
              id=wxID_DLGDELIVERYBTNEDIT)

        self.btnDel = wx.Button(id=wxID_DLGDELIVERYBTNDEL,
              label=u'\u5220\u9664', name=u'btnDel', parent=self,
              pos=wx.Point(264, 8), size=wx.Size(93, 26), style=0)
        self.btnDel.Bind(wx.EVT_BUTTON, self.OnBtnDelButton,
              id=wxID_DLGDELIVERYBTNDEL)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.btnDel.Show(False)
        self.btnEdit.Show(False)
        
        self.lc = MyListCtrlDelivery(self)
        self.lc.Move((8, 50))
        self.lc.SetSize(wx.Size(600, 400))
        self.lc.Bind(wx.EVT_LEFT_DCLICK, self.OnDClick)

    def setPeer(self, peerObj):
        self.m_peer = peerObj
        self.lc.refresh({'peerId':peerObj.getKeyVal()})
    
    def getSelectObj(self):
        return self.m_delivery
        
    def OnDClick(self, event):
        item = self.lc.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        if (item == -1):
            return
        
        # id = self.lc.getDlvyId(item)
        # self.m_delivery = CDataDelivery.findObj(id)
        self.m_delivery = self.lc.getDlvyId(item)
        self.EndModal(wx.ID_OK)
        
    def OnBtnNewButton(self, event):
    #     import DlgDeliveryEditor
        
    #     dlg = DlgDeliveryEditor.create(self)
    #     if (dlg.ShowModal() == wx.ID_OK):
    #         self.m_delivery = dlg.m_delivery
    #         self.EndModal(wx.ID_OK)
        dlg = wx.TextEntryDialog(
                self, u'添加配送方式',u'添加配送方式', '')
        if dlg.ShowModal() == wx.ID_OK:
            self.m_delivery = dlg.GetValue()
            self.EndModal(wx.ID_OK)

    def OnBtnEditButton(self, event):
        event.Skip()

    def OnBtnDelButton(self, event):
        event.Skip()
